﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ChongJu.ModelManager.Calibration
{
    public class CalibrationSDKModel
    {
        public int Index { get; set; }


        public double StandR { get; set; }

        public double StandG { get; set; }

        public double StandB { get; set; }


        public double TestR { get; set; }

        public double TestG { get; set; }

        public double TestB { get; set; }


        public int CameraR { get; set; }

        public int CameraG { get; set; }

        public int CameraB { get; set; }

        public int Luminance { get; set; }


        public int MultiplyR { get; set; }

        public int MultiplyG { get; set; }

        public int MultiplyB { get; set; }

        public int MultiplyLuminance { get; set; }


        public bool IsCameraToLight { get; set; }

        public int ResultR
        {
            get
            {
                return CameraR + MultiplyR;
            }
        }

        public int ResultG
        {
            get
            {
                return CameraG + MultiplyG;
            }
        }

        public int ResultB
        {
            get
            {
                return CameraB + MultiplyB;
            }
        }

        public int ResultLuminance
        {
            get
            {
                return Luminance + MultiplyLuminance;
            }
        }


        public string ImageDir { get; set; }


        public int X { get; set; }

        public int Y { get; set; }

        public int W { get; set; }

        public int H { get; set; }


        public int RemoveRate { get; set; }

        public bool IsComplete { get; set; }

        public int Falg { get; set; }

        public double AllowRange { get; set; }

        public int ImageCount { get; set; }

        /// <summary>
        /// 校准类型
        /// </summary>
        public CalibrationEnum Type { get; set; }

        public string Remark { get; set; }
        //上一次校准的类型
        public CalibrationEnum LastCalibrationType { get; set; }

        /// <summary>
        /// 相机曝光时间
        /// </summary>
        public float Expose { get; set; }   

        /// <summary>
        /// 相机输出延时时间
        /// </summary>
        public int OutDelay { get; set; }

        public int SubValue { get; set; }


        public List<CaliNewSDKViewModel> ToView()
        {
            List<CaliNewSDKViewModel> lst = new List<CaliNewSDKViewModel>();

            if(this.Type == CalibrationEnum.Light)
            {
                var view = new CaliNewSDKViewModel();
                view.Title = "亮度";
                view.Stand = Math.Round((StandR + StandG + StandB) / 3, 2);
                view.Test = Math.Round((TestR + TestG + TestB) / 3, 2);
                view.Luminance = this.Luminance;
                view.MultiplyLuminance = this.MultiplyLuminance;
                view.Remark = this.Remark;
                view.Type = this.LastCalibrationType;
                view.Expose = this.Expose;
                view.OutDelay = this.OutDelay;
                view.SubValue = this.SubValue;
                lst.Add(view);
            }

            else
            {
                //R
                var view = new CaliNewSDKViewModel();
                view.Title = "R";
                view.Stand = this.StandR;
                view.Test = this.TestR;
                view.Camera = this.CameraR;
                view.Multiply = this.MultiplyR;
                view.Result = this.ResultR;
                view.Remark = this.Remark;
                view.Luminance = this.Luminance;
                view.MultiplyLuminance = 0;
                view.Type = this.LastCalibrationType;
                lst.Add(view);

                //G
                view = new CaliNewSDKViewModel();
                view.Title = "G";
                view.Stand = this.StandG;
                view.Test = this.TestG;
                view.Multiply = this.MultiplyG;
                view.Camera = this.CameraG;
                view.Result = this.ResultG;
                view.Remark = this.Remark;
                view.Luminance = this.Luminance;
                view.MultiplyLuminance = 0;
                view.Type = this.LastCalibrationType;
                lst.Add(view);

                //B
                view = new CaliNewSDKViewModel();
                view.Title = "B";
                view.Stand = this.StandB;
                view.Test = this.TestB;
                view.Multiply = this.MultiplyB;
                view.Camera = this.CameraB;
                view.Result = this.ResultB;
                view.Remark = this.Remark;
                view.Luminance = this.Luminance;
                view.MultiplyLuminance = 0;
                view.Type = this.LastCalibrationType;
                lst.Add(view);
            }

            return lst;
        }

        public CalibrationSDKModel Clone()
        {
            return this.MemberwiseClone() as CalibrationSDKModel;
        }

    }

    public class CaliNewSDKViewModel
    {
        public string Title { get; set; }

        public double Stand { get; set; }

        public double Test { get; set; }

        public double TestSubStand
        {
            get
            {
                return Math.Round(Test - Stand, 2);
            }
        }

        public double Subtract { get; set; }

        public double Rate { get; set; }

        public int Multiply { get; set; }

        public int Camera { get; set; }

        public int Result { get; set; }

        public int Luminance { get; set; }

        public int MultiplyLuminance { get; set; }

        public int ResultLuminance
        {
            get
            {
                return Luminance + MultiplyLuminance;
            }
        }

        /// <summary>
        /// 校准类型
        /// </summary>
        public CalibrationEnum Type { get; set; }

        /// <summary>
        /// 相机曝光时间
        /// </summary>
        public float Expose { get; set; }

        /// <summary>
        /// 相机输出延时时间
        /// </summary>
        public int OutDelay { get; set; }

        public int SubValue { get; set; }

        public string Remark { get; set; }
    }

}
